package com.pzhyd.sc.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.pzhyd.sc.util.StringUtil;
import com.whty.aam.client.authentication.AttributePrincipal;
/**
 * 
 * @author 李刚
 * @date 2012-07-15 
 * @version 1.0 修改记录： 修改时间： 修 改 人： 修改内容：
 */
public class LoginFilter implements Filter{

	public void destroy() {
		 
	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain filter) throws IOException, ServletException {
		HttpServletRequest req = (HttpServletRequest)request;
		//进入手动操作,首页请求 不过滤
		String method=req.getParameter("action");
		if("tracesVotedInfo".equals(method)){
			//============判断是否登录成功:为空没有登入
			AttributePrincipal principal = (AttributePrincipal)req.getUserPrincipal();    
			String username = principal.getName();
            
			//账户
			String account=request.getParameter("account");
			//密码
			String password=request.getParameter("password");
			if(!StringUtil.isEmpty(account) && !StringUtil.isEmpty(password)){
				//继续
				filter.doFilter(request,response);
			}else{
				//跳转首页地址
				((HttpServletResponse)response).sendRedirect("http://wap.zhtf.com.cn/");
			}
		}else{
			//继续
			filter.doFilter(request,response);
		}
	}

	
	public void init(FilterConfig arg0) throws ServletException {
	}

}
